package org.miyuki4j.cfgtool;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class CfgAppLauncher {

    public static void main(String[] args) {
        CfgApp app = null;
        try {
            app = CfgAppFactory.auto(args);
            app.init(args);
            app.asyncRun();
            CfgAppKeeper.keep(app);
        } finally {
            if (app != null) {
                try {
                    app.exit();
                    log.info("app [{}] exit success|mode={}, args={}", app.getClass().getSimpleName(), app.runMode(), String.join(" ", args));
                } catch (Exception e) {
                    log.error("app [{}] exit error|mode={}, args={}", app.getClass().getSimpleName(), app.runMode(), String.join(" ", args), e);
                }
            }
        }
    }
}
